import hconfirm from '@/components/hconfirm.vue';
import { createVNode, render, ref, onMounted, onBeforeMount } from 'vue'
import { isEmpty, isFunction } from '@/plugins/util';


export const useConfirm = () => {

    const showConfirm = (config) => {
        config = config || {};
        const containerEle = document.createElement('div');
        containerEle.setAttribute('name', 'hconfirm')
        document.body.append(containerEle);
        const vnode = createVNode(hconfirm, {
            title: config.title,
            content: config.content,
            btn: config.btn,
            styleSet: config.styleSet,
            confirmCallback: config.confirmCallback,
            cancelCallback: config.cancelCallback,
            containerEle: containerEle
        })
        render(vnode, containerEle);
        return containerEle;
    }

    const closeConfirm = (containerEle) => {
        setTimeout(() => {
            containerEle.remove();
        }, 1000);
    }

    return {
        showConfirm,
        closeConfirm
    }

}
